Skip to content

Commit

Permalink
choose record format based on config setting
Browse files Browse the repository at this point in the history
needed for import tool and consistency checker
in enterprise formats, since these tools are in the
community edition.
  • Loading branch information
Max Sumrall committed Feb 25, 2016
1 parent c1d4bda commit 4754d84
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
*/
package org.neo4j.kernel.impl.store.format;

import org.neo4j.kernel.impl.store.format.lowlimit.LowLimit;
import org.neo4j.helpers.Service;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;

/**
* Selects format to use for databases in this JVM, using a system property. By default uses the safest
Expand All @@ -28,16 +30,29 @@
*/
public class InternalRecordFormatSelector
{
public static RecordFormats select()
public static RecordFormats select( Config config )
{
String formatsClassName = System.getProperty( RecordFormats.class.getName(), LowLimit.class.getName() );
try
String key = config.get( GraphDatabaseFacadeFactory.Configuration.record_type );
RecordFormats.Factory potentialCandidate = null;
for ( RecordFormats.Factory candidate : Service.load( RecordFormats.Factory.class ) )
{
return Class.forName( formatsClassName ).asSubclass( RecordFormats.class ).newInstance();
String candidateId = candidate.getKeys().iterator().next();
if ( candidateId.equals( key ) )
{
return candidate.newInstance();
}
else if ( potentialCandidate == null || candidateId.equals( "highlimit" ) )
{
potentialCandidate = candidate;
}
}
catch ( Exception e )
if ( key.equals( "" ) )
{
throw new Error( "Couldn't load specified record format class '" + formatsClassName + "'", e );
return potentialCandidate.newInstance();
}
else
{
throw new IllegalArgumentException( "Invalid configuration for record format." );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.neo4j.kernel.impl.store.format;

import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.store.record.DynamicRecord;
import org.neo4j.kernel.impl.store.record.LabelTokenRecord;
import org.neo4j.kernel.impl.store.record.NodeRecord;
Expand All @@ -30,6 +31,17 @@

public interface RecordFormats
{

abstract class Factory extends Service
{
public Factory( String key, String... altKeys )
{
super( key, altKeys );
}

public abstract RecordFormats newInstance();
}

String storeVersion();

RecordFormat<NodeRecord> node();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.neo4j.kernel.impl.store.format.lowlimit;

import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.store.format.RecordFormats;

@Service.Implementation(RecordFormats.Factory.class)
public class LowLimitFactory extends RecordFormats.Factory
{
public LowLimitFactory()
{
super( "lowlimit" );
}

@Override
public RecordFormats newInstance( )
{
return LowLimit.RECORD_FORMATS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.neo4j.kernel.impl.store.format.highlimit;

import org.neo4j.helpers.Service;
import org.neo4j.kernel.impl.store.format.RecordFormats;

@Service.Implementation(RecordFormats.Factory.class)
public class HighLimitFactory extends RecordFormats.Factory
{
public HighLimitFactory()
{
super( "highlimit" );
}

@Override
public RecordFormats newInstance()
{
return HighLimit.RECORD_FORMATS;
}
}

0 comments on commit 4754d84

Please sign in to comment.