@ -1,14 +1,17 @@
package two.pm.traqtor ;
import java.io.File ;
import java.net.MalformedURLException ;
import java.net.URL ;
import javax.enterprise.context.ApplicationScoped ;
import javax.inject.Singleton ;
import org.apache.cayenne.ObjectContext ;
import org.apache.cayenne.configuration.Constants ;
import org.apache.cayenne.configuration.server.ServerRuntime ;
import org.apache.cayenne.crypto.CryptoModule ;
import org.apache.cayenne.di.Key ;
import org.apache.cayenne.log.JdbcEventLogger ;
import org.apache.cayenne.log.NoopJdbcEventLogger ;
import org.apache.cayenne.query.SQLExec ;
import org.apache.cayenne.resource.ResourceLocator ;
@ -20,24 +23,37 @@ public class CayenneRuntimeFactory {
@Singleton
public ServerRuntime cayenneRuntime ( ) {
if ( runtime = = null ) {
// ClassLoader classLoader = ;
// File file = new File(classLoader.getFile());
// System.out.println(file.getAbsolutePath());
runtime = ServerRuntime . builder ( ) . addConfig ( "db/cayenne-traqtor.xml" )
. addModule ( binder - > binder . bind ( JdbcEventLogger . class ) . to ( NoopJdbcEventLogger . class ) )
// .addModule(binder ->
// binder.bind(JdbcEventLogger.class).to(NoopJdbcEventLogger.class))
. addModule ( binder - > {
binder . bind ( ResourceLocator . class ) . to ( ClassLoaderResourceLocatorFix . class ) ;
binder . bind ( Key . get ( ResourceLocator . class , Constants . SERVER_RESOURCE_LOCATOR ) )
binder . bind ( ResourceLocator . class )
. to ( ClassLoaderResourceLocatorFix . class ) ;
binder . bind ( Key . get ( ResourceLocator . class ,
Constants . SERVER_RESOURCE_LOCATOR ) )
. to ( ClassLoaderResourceLocatorFix . class ) ;
} ) . build ( ) ;
} )
. addModule ( CryptoModule . extend ( )
. keyStore ( this . getClass ( ) . getClassLoader ( )
. getResource ( "db/traqtor.keystore" ) ,
"secret" . toCharArray ( ) , "key0" )
. compress ( )
// .useHMAC()
. module ( ) )
. build ( ) ;
ObjectContext context = runtime . newContext ( ) ;
SQLExec . query (
"CREATE TABLE IF NOT EXISTS user (email VARCHAR(36) NULL, id VARBINARY(36) NOT NULL, PRIMARY KEY (id));" )
. execute ( context ) ;
SQLExec . query (
"CREATE SEQUENCE IF NOT EXISTS pk_user START WITH -9223372036854775808 INCREMENT BY 20 CACHE 1;" )
SQLExec . query ( "CREATE TABLE IF NOT EXISTS system_user (id bigint NOT NULL, CRYPTO_password varchar(2048) NOT NULL, CRYPTO_email varchar(2048) NOT NULL, PRIMARY KEY (id));"
+ "CREATE SEQUENCE IF NOT EXISTS pk_system_user INCREMENT 20 MINVALUE -9223372036854775807;" )
. execute ( context ) ;
context . commitChanges ( ) ;
}
return runtime ;
// return
// ServerRuntime.builder().dataSource(dataSource).addConfig("db/cayenne-test.xml").addModule(binder