📄 basedatabase.java
字号:
types.addColumn(new Column("PRECISION",new IntegerType())); types.addColumn(new Column("LITERAL_PREFIX",new StringType())); types.addColumn(new Column("LITERAL_SUFFIX",new StringType())); types.addColumn(new Column("CREATE_PARAMS",new StringType())); types.addColumn(new Column("NULLABLE",new IntegerType())); types.addColumn(new Column("CASE_SENSITIVE",new BooleanType())); types.addColumn(new Column("SEARCHABLE",new ShortType())); types.addColumn(new Column("UNSIGNED_ATTRIBUTE",new BooleanType())); types.addColumn(new Column("FIXED_PREC_SCALE",new BooleanType())); types.addColumn(new Column("AUTO_INCREMENT",new BooleanType())); types.addColumn(new Column("LOCAL_TYPE_NAME",new StringType())); types.addColumn(new Column("MINIMUM_SCALE",new ShortType())); types.addColumn(new Column("MAXIMUM_SCALE",new ShortType())); types.addColumn(new Column("SQL_DATA_TYPE",new IntegerType())); types.addColumn(new Column("SQL_DATETIME_SUB",new IntegerType())); types.addColumn(new Column("NUM_PREC_RADIX",new IntegerType())); addTable(types); addDatabaseModificationListener(new AxionTypesMetaTableUpdater(this)); } { Table seqTable = createSystemTable("AXION_SEQUENCES"); seqTable.addColumn(new Column("SEQUENCE_NAME", new StringType())); seqTable.addColumn(new Column("SEQUENCE_VALUE", new IntegerType())); addTable(seqTable); addDatabaseModificationListener(_seqUpd); } } private void addIndexType(String typename, String factoryclassname) throws AxionException { assertNotNull(typename, factoryclassname); try { IndexFactory factory = (IndexFactory)(getInstanceForClassName(factoryclassname)); addIndexType(typename,factory); } catch(ClassCastException e) { throw new AxionException("Expected IndexFactory for \"" + factoryclassname + "\"."); } } private void addIndexType(String typename, IndexFactory factory) throws AxionException { assertNotNull(typename, factory); if(null != _indexTypes.get(typename.toUpperCase())) { throw new AxionException("An index type named \"" + typename + "\" already exists (" + _indexTypes.get(typename.toUpperCase()) + ")"); } _log.debug("Adding index type \"" + typename + "\" (" + factory+ ")."); _indexTypes.put(typename.toUpperCase(),factory); } private void addDataType(String typename, String factoryclassname) throws AxionException { assertNotNull(typename, factoryclassname); try { DataTypeFactory factory = (DataTypeFactory)(getInstanceForClassName(factoryclassname)); addDataType(typename, factory); } catch(ClassCastException e) { throw new AxionException("Expected DataType for \"" + factoryclassname + "\"."); } } private void addDataType(String typename, DataTypeFactory factory) throws AxionException { assertNotNull(typename, factory); if(null != _dataTypes.get(typename.toUpperCase())) { throw new AxionException("A type named \"" + typename + "\" already exists (" + _dataTypes.get(typename.toUpperCase()) + ")"); } _log.debug("Adding type \"" + typename + "\" (" + factory+ ")."); DataType type = factory.makeNewInstance(); typename = typename.toUpperCase(); _dataTypes.put(typename, type); DatabaseTypeEvent e = new DatabaseTypeEvent(typename, type); Iterator i = getDatabaseModificationListeners().iterator(); while (i.hasNext()) { DatabaseModificationListener cur = (DatabaseModificationListener)i.next(); cur.typeAdded(e); } } private void addFunction(String fnname, String factoryclassname) throws AxionException { assertNotNull(fnname, factoryclassname); try { FunctionFactory factory = (FunctionFactory)(getInstanceForClassName(factoryclassname)); addFunction(fnname,factory); } catch(ClassCastException e) { throw new AxionException("Expected FunctionFactory for \"" + factoryclassname + "\"."); } } private void addFunction(String fnname, FunctionFactory factory ) throws AxionException { assertNotNull(fnname, factory); if(null != _functions.get(fnname.toUpperCase())) { throw new AxionException("A function named \"" + fnname+ "\" already exists (" + _functions.get(fnname.toUpperCase()) + ")"); } _log.debug("Adding function \"" + fnname + "\" (" + factory + ")."); _functions.put(fnname.toUpperCase(),factory); } private ConcreteFunction getFunction(String name) { FunctionFactory factory = (FunctionFactory)(_functions.get(name.toUpperCase())); if(null != factory) { return factory.makeNewInstance(); } else { return null; } } private void assertNotNull(Object obj1, Object obj2) throws AxionException { if(null == obj1|| null == obj2) { throw new AxionException("Neither argument can be null."); } } private Object getInstanceForClassName(String classname) throws AxionException { try { Class clazz = Class.forName(classname); return clazz.newInstance(); } catch(ClassNotFoundException e) { throw new AxionException("Class \"" + classname + "\" not found."); } catch(InstantiationException e) { throw new AxionException("Unable to instantiate class \"" + classname + "\" via a no-arg constructor."); } catch(IllegalAccessException e) { throw new AxionException("IllegalAccessException trying to instantiate class \"" + classname + "\" via a no-arg constructor."); } } private DataType getDataType(String tablename, String columnname) throws AxionException { Table table = getTable(tablename); if(null == table) { throw new AxionException("Table " + tablename + " not found."); } Column col = table.getColumn(columnname); if(null == col) { throw new AxionException("Column " + columnname + " not found in table " + tablename + "."); } return col.getDataType(); } private Selectable resolveColumn(ColumnIdentifier column, TableIdentifier[] tables) throws AxionException { if(null == column) { return null; } if (column.getTableName() != null && getSequence(column.getTableName()) != null) { return getSequence(column.getTableName()); } if(column.getTableName() != null && column.getTableAlias() != null && column.getDataType() != null) { // if the column already has a table name, table alias and data type, we're done return column; } else { boolean foundit = false; for(int i=0;i<tables.length;i++) { if(null != tables[i].getTableAlias() && tables[i].getTableAlias().equals(column.getTableName())) { // if the column's table name is the table's alias name, // the column belongs to this table column.setTableIdentifier(tables[i]); foundit = true; break; } else if(tables[i].getTableName().equals(column.getTableName())) { // else if the column's table name is the table's name // the column belongs to this table column.setTableIdentifier(tables[i]); foundit = true; break; } else if(null == column.getTableName()) { // else if the column has no table name if("*".equals(column.getName())) { // if the column is "*", we're done foundit = true; break; } else { // look for it in this table Table table = getTable(tables[i]); if(null == table) { throw new AxionException("Table " + tables[i] + " not found."); } if(table.hasColumn(column)) { column.setTableIdentifier(tables[i]); foundit = true; break; } } } } if(foundit) { if(column.getTableName() != null) { column.setDataType(getDataType(column.getTableName(),column.getName())); } return column; } else { throw new AxionException("Couldn't resolve column " + column); } } } private ConcreteFunction resolveFunctionIdentifier(FunctionIdentifier fn, TableIdentifier[] tables) throws AxionException { _log.debug("resolveFunction(): " + fn); ConcreteFunction cfn = getFunction(fn.getName()); if(null == cfn) { _log.debug("resolveFunction(): no function found"); throw new AxionException("No function matching " + fn); } else { _log.debug("resolveFunction(): found " + cfn); for(int i=0;i<fn.getArgumentCount();i++) { cfn.addArgument(resolveSelectable(fn.getArgument(i),tables)); } if(!cfn.isValid()) { _log.info("resolveFunction(): function isn't valid"); throw new AxionException("Function " + fn + " isn't valid."); } return cfn; } } private Expression resolveExpression(ExpressionIdentifier expr, TableIdentifier[] tables) throws AxionException { _log.debug("resolveExpression(): " + expr); Expression expression = new Expression(); Selectable left = resolveSelectable(expr.getLeftSelectable(), tables); if (left instanceof AggregateFunction) { throw new AxionException("Use of aggregate functions in expression is not allowed."); } expression.setLeftSelectable(left); Selectable right = resolveSelectable(expr.getRightSelectable(), tables); if (right instanceof AggregateFunction) { throw new AxionException("Use of aggregate functions in expression is not allowed."); } expression.setRightSelectable(right); expression.setOperationType(expr.getOperationType()); return expression; } //-------------------------------------------------------------- Attributes private String _name = null; private boolean _readOnly = false; private List _listeners = new ArrayList(); private Map _tables = new HashMap(); private Map _dataTypes = new HashMap(); private Map _functions = new HashMap(); private Map _indexTypes = new HashMap(); private Map _tableTypes = new HashMap(); private Map _sequences = new HashMap(); private TransactionManager _transactionManager = new TransactionManagerImpl(this); private DatabaseModificationListener _colUpd = new AxionColumnsMetaTableUpdater(this); private DatabaseModificationListener _seqUpd = new AxionSequencesMetaTableUpdater(this); private static Log _log = LogFactory.getLog(BaseDatabase.class); private static Properties _props = null;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -