@ -7,19 +7,17 @@ import ru.simsonic.rscPermissions.DataTypes.Destination;
import ru.simsonic.rscPermissions.DataTypes.EntityType ;
import ru.simsonic.rscPermissions.DataTypes.EntityType ;
import ru.simsonic.rscPermissions.DataTypes.RowEntity ;
import ru.simsonic.rscPermissions.DataTypes.RowEntity ;
import ru.simsonic.rscPermissions.DataTypes.RowInheritance ;
import ru.simsonic.rscPermissions.DataTypes.RowInheritance ;
import ru.simsonic.rscPermissions.DataTypes.RowLadder ;
import ru.simsonic.rscPermissions.DataTypes.RowPermission ;
import ru.simsonic.rscPermissions.DataTypes.RowPermission ;
import ru.simsonic.rscPermissions.InternalCache.AbstractPermissionsCache ;
import ru.simsonic.rscPermissions.InternalCache.AbstractPermissionsCache ;
import ru.simsonic.rscPermissions.MainPluginClass ;
import ru.simsonic.rscPermissions.BukkitPluginMain ;
import ru.simsonic.rscPermissions.Settings ;
import ru.simsonic.utilities.ConnectionMySQL ;
import ru.simsonic.utilities.ConnectionMySQL ;
public class BackendMySQL extends ConnectionMySQL implements Backend
public class BackendMySQL extends ConnectionMySQL implements Backend
{
{
protected final MainPluginClass plugin ;
protected final BukkitPluginMain plugin ;
protected static enum WorkMode { read , write , none , }
protected static enum WorkMode { read , write , none , }
protected WorkMode RememberWork ;
protected WorkMode RememberWork ;
public BackendMySQL ( MainPluginClass plugin )
public BackendMySQL ( BukkitPluginMain plugin )
{
{
this . plugin = plugin ;
this . plugin = plugin ;
}
}
@ -86,14 +84,13 @@ public class BackendMySQL extends ConnectionMySQL implements Backend
public synchronized void fetchIntoCache ( AbstractPermissionsCache cache )
public synchronized void fetchIntoCache ( AbstractPermissionsCache cache )
{
{
cleanupTables ( ) ;
cleanupTables ( ) ;
MainPluginClass . consoleLog . log ( Level . INFO ,
BukkitPluginMain . consoleLog . log ( Level . INFO ,
"[rscp] Fetched {0}e, {1}p, {2}i, {3}l, from \"{4}\"." ,
"[rscp] Fetched {0}e, {1}p, {2}i, from \"{4}\"." ,
new Object [ ]
new Object [ ]
{
{
Integer . toString ( cache . ImportEntities ( fetchEntities ( ) ) ) ,
Integer . toString ( cache . ImportEntities ( fetchEntities ( ) ) ) ,
Integer . toString ( cache . ImportPermissions ( fetchPermissions ( ) ) ) ,
Integer . toString ( cache . ImportPermissions ( fetchPermissions ( ) ) ) ,
Integer . toString ( cache . ImportInheritance ( fetchInheritance ( ) ) ) ,
Integer . toString ( cache . ImportInheritance ( fetchInheritance ( ) ) ) ,
Integer . toString ( cache . ImportLadders ( fetchLadders ( ) ) ) ,
RememberName ,
RememberName ,
} ) ;
} ) ;
}
}
@ -117,7 +114,7 @@ public class BackendMySQL extends ConnectionMySQL implements Backend
}
}
rs . close ( ) ;
rs . close ( ) ;
} catch ( SQLException ex ) {
} catch ( SQLException ex ) {
MainPluginClass . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2e(): {0}" , ex ) ;
BukkitPluginMain . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2e(): {0}" , ex ) ;
}
}
return result . toArray ( new RowEntity [ result . size ( ) ] ) ;
return result . toArray ( new RowEntity [ result . size ( ) ] ) ;
}
}
@ -149,7 +146,7 @@ public class BackendMySQL extends ConnectionMySQL implements Backend
}
}
rs . close ( ) ;
rs . close ( ) ;
} catch ( SQLException ex ) {
} catch ( SQLException ex ) {
MainPluginClass . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2p(): {0}" , ex ) ;
BukkitPluginMain . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2p(): {0}" , ex ) ;
}
}
return result . toArray ( new RowPermission [ result . size ( ) ] ) ;
return result . toArray ( new RowPermission [ result . size ( ) ] ) ;
}
}
@ -182,42 +179,11 @@ public class BackendMySQL extends ConnectionMySQL implements Backend
}
}
rs . close ( ) ;
rs . close ( ) ;
} catch ( SQLException ex ) {
} catch ( SQLException ex ) {
MainPluginClass . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2i(): {0}" , ex ) ;
BukkitPluginMain . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2i(): {0}" , ex ) ;
}
}
return result . toArray ( new RowInheritance [ result . size ( ) ] ) ;
return result . toArray ( new RowInheritance [ result . size ( ) ] ) ;
}
}
@Override
@Override
public synchronized RowLadder [ ] fetchLadders ( )
{
final ArrayList < RowLadder > result = new ArrayList < > ( ) ;
final ResultSet rs = executeQuery ( "SELECT * FROM `{DATABASE}`.`{PREFIX}ladders`;" ) ;
try
{
while ( rs . next ( ) )
{
RowLadder row = new RowLadder ( ) ;
row . id = rs . getInt ( "id" ) ;
row . climber = rs . getString ( "climber" ) ;
if ( "" . equals ( row . climber ) )
row . climber = null ;
row . climberType = EntityType . byValue ( rs . getInt ( "climber_type" ) ) ;
row . ladder = rs . getString ( "ladder" ) ;
String [ ] breaked = row . ladder . split ( Settings . separatorRegExp ) ;
if ( breaked . length = = 2 )
{
row . ladder = breaked [ 0 ] ;
row . instance = breaked [ 1 ] ;
}
row . rank = rs . getInt ( "rank" ) ;
result . add ( row ) ;
}
rs . close ( ) ;
} catch ( SQLException ex ) {
MainPluginClass . consoleLog . log ( Level . WARNING , "[rscp] Exception in rs2l(): {0}" , ex ) ;
}
return result . toArray ( new RowLadder [ result . size ( ) ] ) ;
}
@Override
public synchronized void insertExampleRows ( )
public synchronized void insertExampleRows ( )
{
{
executeUpdateT ( "Insert_example_rows_v1" ) ;
executeUpdateT ( "Insert_example_rows_v1" ) ;
@ -236,37 +202,10 @@ public class BackendMySQL extends ConnectionMySQL implements Backend
executeUpdateT ( "Update_entity_text" ) ;
executeUpdateT ( "Update_entity_text" ) ;
}
}
@Override
@Override
public synchronized void setUserRank ( String user , String ladder , int rank )
{
if ( "" . equals ( user ) | | "" . equals ( ladder ) )
return ;
setupQueryTemplate ( "{USER}" , user ) ;
setupQueryTemplate ( "{LADDER}" , ladder ) ;
setupQueryTemplate ( "{RANK}" , Integer . toString ( rank ) ) ;
executeUpdateT ( "Set_user_rank" ) ;
}
@Override
public synchronized void dropUserFromLadder ( String user , String ladder )
{
String instance = "" ;
String [ ] breaked = ladder . split ( Settings . separatorRegExp ) ;
if ( breaked . length = = 2 )
{
ladder = breaked [ 0 ] ;
instance = breaked [ 1 ] ;
}
if ( "" . equals ( user ) | | "" . equals ( ladder ) )
return ;
setupQueryTemplate ( "{USER}" , user ) ;
setupQueryTemplate ( "{LADDER}" , ladder ) ;
setupQueryTemplate ( "{INSTANCE}" , instance ) ;
executeUpdateT ( "Drop_user_from_ladder" ) ;
}
@Override
public synchronized void addUserParentGroup ( String user , String newGroup )
public synchronized void addUserParentGroup ( String user , String newGroup )
{
{
setupQueryTemplate ( "{USER}" , user ) ;
setupQueryTemplate ( "{USER}" , user ) ;
setupQueryTemplate ( "{PARENT}" , newGroup ) ;
setupQueryTemplate ( "{PARENT}" , newGroup ) ;
executeUpdate ( "INSERT INTO `{DATABASE}`.`{PREFIX}inheritance` (`entity`, `parent`, `inheritance_type`) VALUES ('{USER}', '{PARENT}', b'1');" ) ;
executeUpdate ( "INSERT INTO `{DATABASE}`.`{PREFIX}inheritance` (`entity`, `parent`, `inheritance_type`) VALUES ('{USER}', '{PARENT}', b'1');" ) ;
}
}
}
}