Search in sources :

Example 6 with Table

use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.

the class SessionFactoryBuilder method mapOneToMany.

protected void mapOneToMany(ForeignKey foreignKey) throws NotFoundException, CannotCompileException {
    CtClass cc = getMappedClass(foreignKey.getToTable());
    ClassFile ccFile = cc.getClassFile();
    ConstPool constPool = ccFile.getConstPool();
    Table fromTable = foreignKey.getFromTable();
    CtField field = new CtField(classPool.get(List.class.getName()), foreignKey.getActualManyPropertyName(), cc);
    String referencedClassName = getMappedClassName(fromTable);
    field.setGenericSignature("Ljava/util/List<L" + referencedClassName.replace('.', '/') + ";>;");
    cc.addField(field);
    AnnotationsAttribute fieldAnnotations = new AnnotationsAttribute(constPool, AnnotationsAttribute.visibleTag);
    Annotation annotation;
    annotation = new Annotation(OneToMany.class.getName(), constPool);
    annotation.addMemberValue("targetEntity", new ClassMemberValue(referencedClassName, constPool));
    annotation.addMemberValue("mappedBy", new StringMemberValue(foreignKey.getActualOnePropertyName(), constPool));
    // TODO cascade?
    finalizeRelationshipProperty(cc, field, annotation, fieldAnnotations);
}
Also used : ConstPool(javassist.bytecode.ConstPool) ClassFile(javassist.bytecode.ClassFile) Table(com.manydesigns.portofino.model.database.Table) AnnotationsAttribute(javassist.bytecode.AnnotationsAttribute)

Example 7 with Table

use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.

the class SessionFactoryBuilder method deriveMappedClassName.

@NotNull
public static String deriveMappedClassName(Table table, EntityMode entityMode) {
    String packageName = table.getSchema().getQualifiedName().toLowerCase();
    String className = table.getActualEntityName();
    if (entityMode == EntityMode.POJO) {
        className = toJavaLikeName(className);
    } else {
        className = className.replaceAll("-|\\h", "");
    }
    if (Character.isDigit(className.charAt(0))) {
        className = "_" + className;
    }
    String fullName = packageName + "." + className;
    if (entityMode == EntityMode.POJO) {
        fullName = ensureValidJavaName(fullName);
    }
    for (Table other : table.getSchema().getDatabase().getAllTables()) {
        if (other != table && other.getActualJavaClass() != null && other.getActualJavaClass().getName().equals(fullName)) {
            fullName += "_1";
        }
    }
    return fullName;
}
Also used : Table(com.manydesigns.portofino.model.database.Table) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Table

use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.

the class CrudActionTest method setupJPetStore.

protected void setupJPetStore() throws Exception {
    Session session = persistence.getSession("jpetstore");
    session.doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("sql/jpetstore-postgres-schema.sql"));
            RunScript.execute(connection, reader);
            reader = new InputStreamReader(getClass().getResourceAsStream("sql/jpetstore-postgres-dataload.sql"));
            RunScript.execute(connection, reader);
        }
    });
    session.getTransaction().commit();
    persistence.syncDataModel("jpetstore");
    // Table ordersTable = DatabaseLogic.findTableByName(persistence.getModel(), "jpetstore", "PUBLIC", "ORDERS");
    // ordersTable.getPrimaryKey().getPrimaryKeyColumns().get(0).setGenerator(new TableGenerator());
    Table supplierTable = DatabaseLogic.findTableByName(persistence.getModel(), "jpetstore", "PUBLIC", "SUPPLIER");
    supplierTable.getPrimaryKey().getPrimaryKeyColumns().get(0).setGenerator(new IncrementGenerator());
// Table testTable = DatabaseLogic.findTableByName(persistence.getModel(), "jpetstore", "PUBLIC", "TEST");
// testTable.getPrimaryKey().getPrimaryKeyColumns().get(0).setGenerator(new SequenceGenerator());
}
Also used : Table(com.manydesigns.portofino.model.database.Table) InputStreamReader(java.io.InputStreamReader) SQLException(java.sql.SQLException) Work(org.hibernate.jdbc.Work) Connection(java.sql.Connection) IncrementGenerator(com.manydesigns.portofino.model.database.IncrementGenerator) Session(org.hibernate.Session)

Example 9 with Table

use of com.manydesigns.portofino.model.database.Table in project Portofino by ManyDesigns.

the class UsersAction method createApplication.

@Path("/check-wizard")
@POST
public boolean createApplication(WizardInfo wizard) throws Exception {
    Table userTable = UpstairsAction.getTable(persistence.getModel(), wizard.usersTable);
    if (userTable == null) {
        return true;
    }
    Column userPasswordColumn = UpstairsAction.getColumn(userTable, wizard.userPasswordProperty);
    if (userPasswordColumn == null) {
        return true;
    }
    if (userPasswordColumn.getActualJavaType() != String.class) {
        RequestMessages.addErrorMessage("The type of the password column, " + userPasswordColumn.getColumnName() + ", is not string: " + userPasswordColumn.getActualJavaType().getSimpleName());
        return false;
    }
    if (userPasswordColumn.getLength() < 32) {
        // TODO: would make sense to conditionalize this on the encryption algorithm + encoding combination
        RequestMessages.addErrorMessage("The length of the password column, " + userPasswordColumn.getColumnName() + ", is less than 32: " + userPasswordColumn.getLength());
        return false;
    }
    return true;
}
Also used : Table(com.manydesigns.portofino.model.database.Table) Column(com.manydesigns.portofino.model.database.Column) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

Table (com.manydesigns.portofino.model.database.Table)9 Column (com.manydesigns.portofino.model.database.Column)3 AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)3 ClassFile (javassist.bytecode.ClassFile)3 ConstPool (javassist.bytecode.ConstPool)3 PersistentClass (org.hibernate.mapping.PersistentClass)3 Updatable (com.manydesigns.elements.annotations.Updatable)2 IOException (java.io.IOException)2 javax.persistence (javax.persistence)2 FileObject (org.apache.commons.vfs2.FileObject)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 Metadata (org.hibernate.boot.Metadata)2 MetadataBuilder (org.hibernate.boot.MetadataBuilder)2 MetadataSources (org.hibernate.boot.MetadataSources)2 BootstrapServiceRegistry (org.hibernate.boot.registry.BootstrapServiceRegistry)2 BootstrapServiceRegistryBuilder (org.hibernate.boot.registry.BootstrapServiceRegistryBuilder)2 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)2 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 Component (org.hibernate.mapping.Component)2 ServiceRegistry (org.hibernate.service.ServiceRegistry)2